var FoodModel = require('../models').Food;


module.exports = {
    addAssessByFoodId: addAssessByFoodId,
    getAllAssessByFoodItemId: getAllAssessByFoodItemId,
    getAssessWithoutRelayByMerchantId: getAssessWithoutRelayByMerchantId,
    getAssessWithRelayByMerchantId: getAssessWithRelayByMerchantId,
    updateAssessByOrderId: updateAssessByOrderId
}

function addAssessByFoodId(id, assess, callback) {
    FoodModel.update({food_id: id},
        {
            $push: {
                'assess': assess
            },
        }
        , callback)

}

function updateAssessByOrderId(id, reply, callback) {
    FoodModel.update({'assess.assess_id': id},
        {
            $set: {
                'assess.reply': reply
            },
        }
        , callback)

}

function getAllAssessByFoodItemId(foodItemId, callback) {
    FoodModel.findOne({_id: foodItemId}, callback);
}

function getAssessWithoutRelayByMerchantId(merchant_id, callback) {
    FoodModel.find({merchant_id: merchant_id,'assess.replay':null}, callback);
}

function getAssessWithRelayByMerchantId(merchant_id, callback) {
    FoodModel.find({merchant_id: merchant_id,'assess.replay':{$ne:null}}, callback);
}

